var e = a(require("../../libs/mini/create")), t = a(require("../../store/index"));

a(require("../../utils/storage"));

function a(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}

var i = getApp(), n = null;

e.default.Page(t.default, {
    use: [ "customLoading", "custom", "userInfo" ],
    data: {
        singlePage: "singlePage" === i.globalData.mode,
        menuList: [],
        defaultAvatar: i.globalData.moduleHost + "/resources/image/default_user.png",
        defaultInvite: i.globalData.moduleHost + "/resources/image/invite.png",
        defaultManager: i.globalData.moduleHost + "/resources/image/invite.png",
        showPopupImage: !1,
        currentItem: {}
    },
    onLoad: function() {
        var e = this;
        t.default.getCustom(function(t) {
            console.log("custom: ", t), e._initAd(), t.title && wx.setNavigationBarTitle({
                title: t.title
            });
        });
    },
    _initAd: function() {
        var e = this.data.$.custom;
        wx.createInterstitialAd && 1 == e.ad_screen_active && (n = wx.createInterstitialAd({
            adUnitId: e.ad_screen || ""
        })).onError(function(e) {
            console.error("插屏广告加载失败：", e);
        });
    },
    onShow: function() {
        var e = this.data.$.custom;
        setTimeout(function() {
            n && 1 == e.ad_screen_active && n.show().catch(function(e) {
                console.error("插屏广告加载失败：", e);
            });
        }, 1e3 * e.ad_screen_timeout);
    },
    onClose: function() {
        this.setData({
            showPopupImage: !1
        });
    },
    handleBannerItemClick: function(e) {
        var t = e.currentTarget.dataset.item;
        switch (t.type) {
          case "h5":
            t.url ? wx.navigateTo({
                url: "/pages/webview/index?src=" + t.url
            }) : i.utils.modalText("未设置跳转内容，操作失败");
            break;

          case "mini":
            wx.navigateToMiniProgram({
                appId: t.appid,
                path: decodeURIComponent(t.url),
                fail: function(e) {
                    "navigateToMiniProgram:fail invalid appid" === (e = e.errMsg) ? i.utils.modalText("跳转失败，可能是小程序路径或appid填写错误") : "navigateToMiniProgram:fail can't navigate to myself" === e && wx.navigateTo({
                        url: decodeURIComponent(t.url)
                    });
                }
            });
        }
    },
    handleItemClick: function(e) {
        var t = e.currentTarget.dataset.item;
        switch (t.type) {
          case "h5":
            t.url ? wx.navigateTo({
                url: "/pages/webview/index?src=" + t.url
            }) : i.utils.modalText("未设置内容，操作失败");
            break;

          case "image":
            t.content ? this.setData({
                showPopupImage: !0,
                currentItem: {
                    content: t.content
                }
            }) : i.utils.modalText("未设置内容，操作失败");
            break;

          case "text":
            t.content ? wx.showModal({
                title: t.title || "",
                content: t.content,
                showCancel: !1,
                confirmText: t.confirm_text || "我知道了"
            }) : i.utils.toastText("未设置内容，操作失败");
            break;

          case "mini":
            if (!t.appid) return void wx.navigateTo({
                url: t.url
            });
            wx.navigateToMiniProgram({
                appId: t.appid,
                path: decodeURIComponent(t.url),
                fail: function(e) {
                    "navigateToMiniProgram:fail invalid appid" === (e = e.errMsg) ? i.utils.modalText("跳转失败，可能是小程序路径或appid填写错误") : "navigateToMiniProgram:fail can't navigate to myself" === e && wx.navigateTo({
                        url: t.url
                    });
                }
            });
        }
    },
    handleCreateWifi: function() {
        wx.navigateTo({
            url: "/wifi/edit/index"
        });
    },
    handleManagerClick: function() {
        wx.navigateTo({
            url: "/wifi/list/index"
        });
    },
    handleInvite: function() {
        wx.navigateTo({
            url: "/pages/invite/index"
        });
    },
    handleMember: function() {
        wx.navigateTo({
            url: "/pages/member/index"
        });
    },
    onShareAppMessage: function() {
        var e = this.data.$.custom || {};
        return {
            title: e.share_title || "无需密码，一键连WiFi",
            path: "/pages/home/index?share=1&uid=" + this.data.$.userInfo.id,
            imageUrl: e.share_icon || i.globalData.moduleHost + "/resources/image/wifi_square2.png"
        };
    },
    onShareTimeline: function() {
        var e = this.data.$.custom || {};
        return {
            title: e.share_title || "点击创建您的专属WiFi",
            imageUrl: e.share_icon || i.globalData.moduleHost + "/resources/image/wifi_square2.png"
        };
    }
});